package com.lingyi.algorithm.lab4;

import com.lingyi.algorithm.lab2.Node;

/**
 * 链队列
 * @author chenweilong
 * @email 1433471850@qq.com
 * @date 2020-08-20 16:34
 */
public class ChainQueue {



    private Node<Integer> head;

    private Node<Integer> tail;

    private Node<Integer> node;

    public ChainQueue() {
        node = new Node<>();
        head = node;
        tail = node;
    }

    public void push(Integer data) {
        Node<Integer> newNode = new Node<>();
        newNode.setT(data);
        tail.setNext(newNode);
        tail = newNode;
    }


    public Integer dequeue () {
        if (head.getNext() == null) {
            System.out.println("队列是空的");
            return null;
        }
        Node<Integer> next = head.getNext();
        head = next;
        return next.getT();
    }

    public void print() {
        Node<Integer> printNode = head;
        while (printNode != null) {
            System.out.println(printNode.getT());
            printNode = printNode.getNext();
        }
    }


    public static void main(String[] args) {

        ChainQueue chainQueue = new ChainQueue();
        Integer dequeue = chainQueue.dequeue();
        System.out.println(dequeue);


        chainQueue.push(1);
        chainQueue.push(1);
        chainQueue.push(1);

        Integer dequeue1 = chainQueue.dequeue();
        System.out.println(dequeue1);

        Integer dequeue2 = chainQueue.dequeue();
        System.out.println(dequeue2);

        Integer dequeue3 = chainQueue.dequeue();
        System.out.println(dequeue3);

        Integer dequeue4 = chainQueue.dequeue();
        System.out.println(dequeue4);



    }

}
